<template>
	<view class="body">
		<image src="../../static/image/01.png" mode="widthFix" class="bg"></image>
		<u-navbar
		title="首页"
		:autoBack="true"
		:background="{
		background:'transparent'
		}"
		:border-bottom="false"
		titleSize="28rpx" titleColor="#333"
		back-icon-color="#333"
		:isBack="false"
		:isFixed="false"
		/>
		<myLocation></myLocation>
		
		<view class="container pl30 pr30 pt20">
			<banner :list="bannerdata.list"></banner>
			
			<view class="f36 c3 mt30 mb30 bold">
				陪练服务
			</view>
			
			<classItem v-for="item in data" :data="item" :key="item.id" @click="$go('/pages/classDetail/classDetail?id='+item.id)"></classItem>
			<view class="t-flex center f26  c6 pt20 pb20">
				{{loading?'正在获取更多...':"没有更多了..."}}
			</view>
			<empty msg="暂无陪练服务" v-if="!data.length"></empty>
			<view class="bpad"></view>
			
		</view>	
	</view>
	<contact></contact>
</template>

<script setup lang="ts">
import { reactive } from 'vue';
import { bannerList } from '../../api';
import { onLoad,onPullDownRefresh,onReachBottom,onShareAppMessage,onShareTimeline,onUnload } from "@dcloudio/uni-app"
import { usePaging } from '../../lib/ts/util';
import { useStore } from '../../store';
	
	const store = useStore()
	
	onLoad(()=>{
		bannerdata.init()
		reload()
	})
	onPullDownRefresh(()=>{
		reload()
	})
	onReachBottom(()=>{
		getMore()
	})
	onShareAppMessage(()=>{
		let sf_pid = 0
		let xy_pid = 0
		if(store.userinfo){
			sf_pid = store.userinfo.is_sf==1?store.userinfo.id:0
			xy_pid = store.userinfo.is_sf==1?0:store.userinfo.id
		}		
		return {
			title:'首道汽车陪驾',
			imageUrl:'/static/logo.png',
			path:`/pages/index/index?sf_pid=${sf_pid}&xy_pid=${xy_pid}`
		}
	})
	onShareTimeline(()=>{
		let sf_pid = 0
		let xy_pid = 0
		if(store.userinfo){
			sf_pid = store.userinfo.is_sf==1?store.userinfo.id:0
			xy_pid = store.userinfo.is_sf==1?0:store.userinfo.id
		}
		return {
			title:'首道汽车陪驾',
			imageUrl:'/static/logo.png',
			query:`sf_pid=${sf_pid}&xy_pid=${xy_pid}`
		}
	})
	onUnload(()=>{
		uni.$off('locationUpdate')
	})
	uni.$on('locationUpdate',()=>{
		reload()
	})
	
	
	let bannerdata = reactive({
		list:[],
		async init(){
			bannerdata.list = await bannerList(1)
		}
	})
	
	const {
		data,
		reload,
		getMore,
		loading
	} = usePaging('/api/homeinfo/GoodsList')
	

	
</script>

<style scoped lang="scss">
	.bg{
		position: absolute;
		width: 100%;
	}
	.body{
		min-height: 100vh;
		background-color: #fff;
		
	}
	
</style>